package com.foftact.etfrank;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.foftact.Foftact;
import com.foftact.etfrank.mapper.ETFRankMapper;
import com.foftact.etfrank.service.ETFRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.List;

@SpringBootTest(classes= Foftact.class)
public class ETFRankTestng extends AbstractTestNGSpringContextTests {

    @Autowired
    ETFRankService etfRankService;

    @Autowired
    ETFRankMapper etfRankMapper;

    @Test
    public void test() throws Exception {
        etfRankService.fetchAndSaveETFRankData();
        List<ETFRank> allETFRank = etfRankService.getAllETFRank();
        Assert.assertTrue(allETFRank.size() > 1200);
    }

    @Test
    public void test_select() throws Exception {
        List<ETFRank> etfRanks = etfRankMapper.selectByRank("weekly_growth_rate", "desc", 10000);
        System.out.println(JSON.toJSONString(etfRanks,  JSONWriter.Feature.PrettyFormat));
        Assert.assertTrue(etfRanks.size() > 1200);
    }

}
